C#########################################################
C This file is part of OpenAD released under the LGPL.   #
C The full COPYRIGHT notice can be found in the top      #
C level directory of the OpenAD distribution             #
C#########################################################
C
C$OPENAD XXX File_start [head.f]
      SUBROUTINE head(X, Y)
          use OAD_tape
          use OAD_rev

C original arguments get inserted before version
C         ! and declared here together with all local variables
C         ! generated by xaifBooster

      use OAD_active
      use w2f__types
      use oad_intrinsics
      use oad_intrinsics
      use oad_intrinsics
      IMPLICIT NONE
C
C     **** Parameters and Result ****
C
      type(active) :: X(1:2)
      type(active) :: Y(1:4)
C
C     **** Local Variables and Functions ****
C
      type(active) :: T1
      type(active) :: T2
      type(active) :: Y1
      type(active) :: Y2
      type(active) :: Y3
      type(active) :: Y4
C
C     **** Top Level Pragmas ****
C
C$OPENAD INDEPENDENT(X)
C$OPENAD DEPENDENT(Y)
C
C     **** Statements ****
C


          integer iaddr
          external iaddr
C$OPENAD XXX Template ad_template.f
C$OPENAD XXX Template ad_template.f

         if (our_rev_mode%plain) then
C original function
      T1%v = (X(1)%v+X(2)%v)
      T2%v = (-T1%v)
      Y1%v = T2%v
      Y2%v = (3.14000010490417480469D00-T2%v)
      Y3%v = T2%v
      Y4%v = (T1%v+T2%v)
      Y(1)%v = Y1%v
      Y(2)%v = Y2%v
      Y(3)%v = Y3%v
      Y(4)%v = Y4%v
          end if
          if (our_rev_mode%tape) then
C taping
      T1%v = (X(1)%v+X(2)%v)
      T2%v = (-T1%v)
      Y1%v = T2%v
      Y2%v = (3.14000010490417480469D00-T2%v)
      Y3%v = T2%v
      Y4%v = (T1%v+T2%v)
      Y(1)%v = Y1%v
      Y(2)%v = Y2%v
      Y(3)%v = Y3%v
      Y(4)%v = Y4%v
          end if
          if (our_rev_mode%adjoint) then
C adjoint
      Y4%d = Y4%d+Y(4)%d
      Y(4)%d = 0.0d0
      Y3%d = Y3%d+Y(3)%d
      Y(3)%d = 0.0d0
      Y2%d = Y2%d+Y(2)%d
      Y(2)%d = 0.0d0
      T1%d = T1%d-Y(1)%d
      Y(1)%d = 0.0d0
      T1%d = T1%d-Y3%d
      Y3%d = 0.0d0
      T1%d = T1%d+Y2%d
      Y2%d = 0.0d0
      X(2)%d = X(2)%d+T1%d
      X(1)%d = X(1)%d+T1%d
      T1%d = 0.0d0
          end if
        end subroutine head
